home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13138 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  55 lines

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
  2. From: grantp@usa.pipeline.com(Pete Grant)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Newbie Ques: Templates and C++
  5. Date: 23 Mar 1996 21:58:09 GMT
  6. Organization: Pipeline USA
  7. Message-ID: <4j1s5h$am8@news1.h1.usa.pipeline.com>
  8. References: <DoqLy6.H7q@novice.uwaterloo.ca>
  9. NNTP-Posting-Host: 38.8.60.5
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete Grant)
  13. X-Newsreader: Pipeline v3.5.0
  14.  
  15. On Mar 23, 1996 20:22:54 in article <Newbie Ques: Templates and C++>,
  16. 'a2patel@novice.uwaterloo.ca (Aashish-Kaski-Ashman-Patel)' wrote: 
  17.  
  18.  
  19. >Ok.. Here is what I am trying to do: 
  20. >1)  
  21. >Have a class called Dictionary that depends on two other classes (
  22. determined 
  23. >at compile time ). 
  24. >ie. #ifdef HASH 
  25. >class Dictionary Hash-Table; 
  26. >#else-if BST 
  27. >class Dictionary Bst; 
  28. >#endif 
  29. >Now Hashtable is a template class .. defined 
  30. >template <class typeofwhatever>  
  31. >class HashTable 
  32. >{ 
  33. >//whatever; 
  34. >} 
  35. >The class definitions are in a header file, and the code in a normal
  36. source  
  37. >file. The problem is that when I try to compile the source, I get errors. 
  38. >I believe that this is just a syntax probelm.. The error I get is  
  39. >HashTable::HashTable() cannot be defined in the same scope as class
  40. template. 
  41.  
  42. You didn't show the code, however, from the message it appears your syntax 
  43. is incorrect.  It should be something like: 
  44.  
  45. template<class T> 
  46. HashTable<T>::HashTable() {....}; 
  47.  
  48. As for the #ifdef's:   yes, their syntax is correct. 
  49. -- 
  50.  
  51. Pete Grant 
  52. Kalevi, Inc. 
  53. Sofware Engineering
  54.